package com.hyt.it.ogt.kq.main.controller.bm;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.bm.model.vo.CheckOrderList;
import com.hyt.it.ogt.kq.service.bm.model.vo.CheckOrderTotal;
import com.hyt.it.ogt.kq.service.bm.model.vo.CheckVo;
import com.hyt.it.ogt.kq.service.bm.service.ICheckOrderService;
import com.hyt.log.annotation.Log;
import com.hyt.model.PageParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * 账单核查（对账单）
 * 
 * @author wangt
 * @Description:
 * @date: 2020年9月2日 下午3:35:14
 * @version: V1.0
 */
@RestController
@Api(tags = "19.管理端：对账单", value = "账单核查（对账单）")
@ApiSort(value = 19)
@RequestMapping("/bm/checkOrder")
public class CheckOrderController extends BaseController {

	@Autowired
	private ICheckOrderService iCheckOrderService;

	/**
	 * 对账单
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "19.1.1 管理端： 对账单统计列表（type类型，1：报名，2：教材）", notes = "20000:成功")
	@ApiOperationSort(value = 1)
	@GetMapping(value = "/checkOrderTotal")
	public Object checkOrderTotal(String type, PageParam<CheckOrderTotal> pageParam,String projectName) {
        IPage<CheckOrderTotal> page = pageParam;
        page = iCheckOrderService.checkOrderTotal(pageParam, type, projectName, getOfficeId());
        return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	/**
	 * 对账单 - 所有订单
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "19.1.2 管理端： 对账单列表-所有订单（type类型，1：报名，2：教材）", notes = "20000:成功")
	@ApiOperationSort(value = 2)
	@PostMapping(value = "/checkOrderAll")
	public Object checkOrderAll(PageParam<CheckOrderList> pageParam, @RequestBody CheckVo checkVo) {
		IPage<CheckOrderList> page = pageParam;
		List<String> permissionList = null;
		page = iCheckOrderService.checkOrderAll(pageParam, checkVo,permissionList);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	/**
	 * 对账单 -异常订单详情
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "19.1.3 管理端： 对账单列表-异常订单详情列表（type类型，1：报名，2：教材）", notes = "20000:成功")
	@ApiOperationSort(value = 3)
	@RequestMapping(value = "/checkOrderErrorList", method = RequestMethod.POST)
	public Object checkOrderErrorList(@RequestBody CheckVo checkVo, PageParam<CheckOrderList> pageParam) {
		IPage<CheckOrderList> page = pageParam;
		page = iCheckOrderService.checkOrderErrorList(pageParam, checkVo);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	/**
	 * 对账单 -待确认更新
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "19.1.4管理端： 对账单列表-待确认更新列表（type类型，1：报名，2：教材）", notes = "20000:成功")
	@ApiOperationSort(value = 4)
	@RequestMapping(value = "/checkOrderUpdateList", method = RequestMethod.POST)
	public Object checkOrderUpdateList(@RequestBody CheckVo checkVo, PageParam<CheckOrderList> pageParam) {
		IPage<CheckOrderList> page = pageParam;
		page = iCheckOrderService.checkOrderUpdateList(pageParam, checkVo);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	/**
	 * 对账单 -更新历史列表
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "19.1.5管理端： 对账单列表-更新历史列表（type类型，1：报名，2：教材）", notes = "20000:成功")
	@ApiOperationSort(value = 5)
	@RequestMapping(value = "/checkOrderHistoryList", method = RequestMethod.POST)
	public Object checkOrderHistoryList(@RequestBody CheckVo checkVo, PageParam<CheckOrderList> pageParam) {
		IPage<CheckOrderList> page = pageParam;
		page = iCheckOrderService.checkOrderHistoryList(pageParam, checkVo);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	@ApiOperation(value = "19.1.6 管理端： 更新状态接口（type类型，1：报名，2：教材）", notes = "20000:成功,31191601: 正在更新中, 31191602:更新失败，请联系管理员")
	@ApiOperationSort(value = 6)
	@Log(module = "对账单管理", business = "更新状态接口")
	@RequestMapping(value = "/updateStatus", method = RequestMethod.GET)
	public Object updateStatus(String type, String projectId, String orderId) {
		Map<String, String> msg = iCheckOrderService.checkOrderBill(type, projectId, orderId);
		if ("15039".equals(msg.get("code"))) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31191601).data("任务正在更新中...").build();
		}
		if ("15040".equals(msg.get("code"))) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31191602).data("更新失败，请联系管理员").build();
		}
		if ("14001".equals(msg.get("code"))) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(msg).build();
		}
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_31191602).data("更新失败，请联系管理员").build();
	}
	
	
	@ApiOperation(value = "19.1.6 管理端： 异常处理-全部处理/单个处理 (orderId不传入就是处理所有)(status:1 进行处理，2 取消更新)", notes = "20000:成功 ")
	@ApiOperationSort(value = 7)
	@Log(module = "对账单管理", business = "异常处理")
	@RequestMapping(value = "/doneStatus", method = RequestMethod.GET)
	public Object doneStatus(String type, String projectId, String orderId,String status,String bmOrderHistoryId) {
		String  msg = iCheckOrderService.doneStatus(type, projectId, orderId,status,bmOrderHistoryId);
		if ("14001".equals(msg)) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("处理成功！").build();
		}
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("").build();
		
	}
}
